#include "Comm.hpp"

int main()
{
    Fifo fifo(PATH);
    int rfd = open(PATH, O_RDONLY);
    if (rfd < 0)
    {
        cout << "fail to read open fifo errno is " << errno << " strerror is " << strerror(errno) << endl;
        return 1;
    }
    cout << "read open success" << endl;
    char buffer[1024] = {0};
    while (1)
    {
        ssize_t n = read(rfd, buffer, sizeof(buffer) - 1);
        if (n > 0)
        {
            buffer[n] = 0;
            cout << "client say : " << buffer << endl;
        }
        else if (n == 0)
        {
            cout << "client quit,me too" << endl;
            break;
        }
        else
        {
            cout << "fail to read errno is " << errno << " strerror is " << strerror(errno) << endl;
            break;
        }
    }
    close(rfd);
    return 0;
}